package com.imti.mall.product.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.imti.mall.model.pms.pojo.PmsSkuStock;

import com.imti.mall.product.mapper.PmsSkuStockMapper;
import com.imti.mall.product.service.PmsSkuStockService;
import org.springframework.data.annotation.ReadOnlyProperty;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * sku的库存(PmsSkuStock)表服务实现类
 *
 * @author makejava
 * @since 2023-03-03 00:28:52
 */
@Service("pmsSkuStockService")
public class PmsSkuStockServiceImpl extends ServiceImpl<PmsSkuStockMapper, PmsSkuStock> implements PmsSkuStockService {

    @Resource
    private  PmsSkuStockMapper pmsSkuStockMapper;

    @Override
    public List<PmsSkuStock> fetchListSku(Integer pid) {
        QueryWrapper queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("product_id",pid);

        return pmsSkuStockMapper.selectList(queryWrapper);
    }

    @Override
    public int updateSkuStockById(List<PmsSkuStock> pmsSkuStocks) {
        UpdateWrapper updateWrapper=new UpdateWrapper<>();
        int result=0;
        for (int i=0;i< pmsSkuStocks.size();i++){
            updateWrapper.eq("id",pmsSkuStocks.get(i).getId());
            result+=pmsSkuStockMapper.update(pmsSkuStocks.get(i),updateWrapper);
        }
        return result;
    }
}

